<!DOCTYPE html>
<html lang="zh-cmn-Hans">
  <head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="../../static/mobile/default/css/layout.css?v=2"/>
    <link rel="icon" type="image/png" href="../../static/favicon.ico"/>
        <script src="../../static/js/jquery/jquery/2.1.4/jquery.min.js"></script>
    <script src="../../static/js/jquery/jquery.cookie.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
    <script src="../../static/mobile/default/js/page.js?v=1"></script>
    <title>购物车  - 达漂亮</title>
          
<link rel="stylesheet" href="../../static/mobile/default/css/shopCart.css" />


</head>
<body >
  <div class="page ">
    		<div class="page-hd">
            <div class="header base-header bor-1px-b">
                <div class="header-left">
                    <a href="javascript:history.go(-1)" class="left-arrow"></a>
                </div>
                <div class="header-title">购物车</div>
                <div class="header-right">
                    <!-- <a href=""></a> -->
                </div>
            </div>
        </div>
      
<div class="page-bd">
<!-- 页面内容-->
<div class="top"><span class="fs32 color_3">当前购物车共<em>0</em>件商品</span>
<!--<p class="fs28 color_r" data-type='0'>编辑</p>-->
</div>
    <!-- 空购物车 -->
    <div class="emptyBox">
        <img src="../../static/mobile/default/images/emptyCart.png" alt="">
        <div><span class="fs30 color_9">购物车空空如也~</span><a href="/" class="fs30 color_r">去逛逛</a></div>
    </div>
    <!-- 购物车 -->
    <div class="goodslist">
        <a href="javascript:;" class="goCoupons" style="display: none;">
            <p class="fs26 color_3">先领券再下单能享受更多优惠哦!</p>
            <div class="goCouponsBtn"><span class="fs26 color_r">领券</span><img src="../../static/mobile/default/images/rightIcon.png" alt="" class="threeRight"></div>
        </a>
        <ul>

        </ul>
    </div>
    <!-- 失效商品 -->
    <div class="loseGoods" style="display: none;">
        <div class="title"><span class="fs32 fw_b color_3">失效商品</span><p class="fs28 color_r clearInvalid">清空</p></div>

    </div>

</div>
<div class="paying">
    <div class="totalBox ">
        <div class="left">
            <label for="checkall_a">
                <div class="iconBox">
                    <input type="checkbox" class="check checkall" name="checkbox1" id="checkall_a">
                    <i class="icon_checked"></i>
                </div>
                <span class="fs32 fw_b color-3">全选</span>
            </label>
            <p class="fs28 color_9">小计</p>
            <div class="color_3 fs30 num money"><p class="fw_b fm_p">￥</p><em class="fs52 totel_price_1">00</em><p class="totel_price_2">.00</p></div>
        </div>
        <a onclick="settment()" class="right BGcolor_r fs30 color_w"><span class="fw_b">结算</span>(<em id="buyNum">0</em>)</a>
    </div>
</div>
<!-- 编辑 -->
<div class="edit">
    <div class="totalBox">
        <div class="left">
            <label for="checkall_b">
                <div class="iconBox">
                    <input type="checkbox"  class="check checkall" name="checkbox1" id="checkall_b">
                    <i class="icon_checked"></i>
                </div>
                <span class="fs32 fw_b color-3">全选</span>
            </label>
        </div>
        <div class="button fs30 color_w fw_b"><span class="BGcolor_3 delSelGoods">删除</span><span class="BGcolor_r collectGoods">收藏</span></div>
    </div>
</div>
<div class="copyright">
            Copyright © 达漂亮<br>
    </div>
<!--<div class="bottom-tabbar-wrapper">-->
<!--  <div class="bottom-tabbar">-->
<!--            <a href="../../index.html" class="bottom-tabbar__item">-->
<!--        <span class="icon">-->
<!--            <img src="../../static/menuimg/footer_index_a.png"/>-->
<!--            <img class="lhimg" src="../../static/menuimg/footer_index_b.png"/>-->
<!--        </span>-->
<!--          <p class="label">首页</p>-->
<!--      </a>-->
<!--            &lt;!&ndash; <a href="../index/allsort.html" class="bottom-tabbar__item">-->
<!--        <span class="icon">-->
<!--            <img src="../../static/menuimg/footer_cat_a.png"/>-->
<!--            <img class="lhimg" src="../../static/menuimg/footer_cat_b.png"/>-->
<!--        </span>-->
<!--          <p class="label">分类</p>-->
<!--      </a> &ndash;&gt;-->
<!--            <a href="../flow/cart.html" class="bottom-tabbar__item">-->
<!--        <span class="icon">-->
<!--            <img src="../../static/menuimg/footer_cart_a.png"/>-->
<!--            <img class="lhimg" src="../../static/menuimg/footer_cart_b.png"/>-->
<!--        </span>-->
<!--          <p class="label">购物车</p>-->
<!--      </a>-->
<!--            <a href="../order/index.html" class="bottom-tabbar__item">-->
<!--        <span class="icon">-->
<!--            <img src="../../static/menuimg/footer_cat_a.png"/>-->
<!--            <img class="lhimg" src="../../static/menuimg/footer_cat_b.png"/>-->
<!--        </span>-->
<!--          <p class="label">我的订单</p>-->
<!--      </a>-->
<!--            <a href="../../member/center/index.html" class="bottom-tabbar__item">-->
<!--        <span class="icon">-->
<!--            <img src="../../static/menuimg/footer_user_a.png"/>-->
<!--            <img class="lhimg" src="../../static/menuimg/footer_user_b.png"/>-->
<!--        </span>-->
<!--          <p class="label">我的</p>-->
<!--      </a>-->
<!--        </div>-->
<!--</div>-->
<script>
    var index=-1;
    function setSelect(url){
        $('.bottom-tabbar a').each(function (i,val) {
            var thisUrl = $(this).attr('href');
            var sear=new RegExp(thisUrl);
            if(sear.test(url)){
                index=i;
            }
        });
    }
          share()
     function  share(){
    /***用户点击分享到微信圈后加载接口接口*******/
        var url=window.location.href;
        console.log("url:"+url);
            $.ajax({
		    url: "/api/mp/wxconfig",
		    type: "post",
		    data:{shareUrl:url},
		    headers:{ token: $.cookie('code')},
		    dataType: "json",
		    success: function(data){
		         configData = {
                    debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.data.appid, // 必填，公众号的唯一标识
                    timestamp: data.data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
                    signature: data.data.signature,// 必填，签名，见附录1
                    jsApiList : ['hideOptionMenu']
                    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
               };
               
               //step2:注入配置信息
               wx.config(configData);
               //step3:通过ready接口处理成功验证
               wx.ready(function () {
                   // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
//                 alert("执行ready方法");
//                 wx.checkJsApi({
//                      jsApiList: ['chooseImage'] // 需要检测的JS接口列表，所有JS接口列表见附录2,
//                      success: function(res) {
//                      // 以键值对的形式返回，可用的api值true，不可用为false
//                      // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
//                      }
//                 });
                   //接口1:获取网络类型
                    wx.getNetworkType({
                        success: function (res) {
                          oldNet = res.networkType; // 返回网络类型2g，3g，4g，wifi
//                        alert("网络类型"+ oldNet);
                        }
                     });
                   //禁用右上角菜单按钮
                   wx.hideOptionMenu();
		    })
		    },
		    error: function() {
// 			    _alert('ajax request failed!!!!');
			    return;
		    } 
        })

	    
	    
	    }
    $(function (){
        var curUrl = window.location.href;
        setSelect(curUrl);
        if(index==-1){
            var referrer = document.referrer;
            setSelect(referrer);
        }
        $('.bottom-tabbar a').eq(index).addClass('active');
    })
    
    function settment(){
        var sum = 0
         for(var i=0;i<orderIdList.length;i++){
                if(orderIdList[i].checked ==1){
                    sum+=1
                }
            }
            
        if(sum >0){
            window.location.href ='../flow/checkout.html'
        }else{
             _alert('请选择商品结算');
        }
    }
</script>

<script type="text/html" id="goodsLi">
    {{each cartList as item index}}
    <li>
        <div class="checkbox">
            <label for="s{{item.goods_id}}">
                <div class="iconBox">
                    <input type="checkbox" class="check" id="s{{item.goods_id}}" name="s{{item.goods_id}}" value="{{item.goods_id}}" data-rec_id="{{item.goods_id}}" {{item.checked==1?'checked':''}}>
                    <i class="icon_checked"></i>
                </div>
            </label>
            <div class="block">
                <a href='/shop/goods/info/id/goodInfo.html?goodsId={{item.goods_id}}' >
                    <img src="{{item.list_pic_url}}" alt="" class="goodsimg">
                </a>
                <div class="info">
                    <p class="fs28 color_3">{{item.goods_name}}</p>
                    <div class="sign fs28 color_9">{{item.sku_name}}</div>
                    <div class="Money">
                        <div class="left">
                            <div class="color_3 fs24 num">
                                <p class="fw_b fm_p">￥</p><em class="fs36">{{item.retail_price}}</em>元
                            </div>
                            
                            <!-- {{if item.use_integral > 0}}
                            <p class="fw_b fm_p"> + </p><em class="fs36">{{item.use_integral}}</em>积分
                           {{else if item.prom_type == 1}} -->
                            <!-- <div class="couponsPriceType">优惠价</div>
                            {{else if item.shop_price != item.sale_price}}
                            <span class="fs24 color_9">￥{{item.shop_price}}</span>
                            {{/if}} -->
                            
                        </div>

                        <div class="number">
                            <img src="../../static/mobile/default/images/goodsIcon05.png" onClick="editNum(this,'{{item.goods_id}}','down');" class="minus">
                            <input class="fs30 color_3" type="text" readonly value="{{item.number}}">
                            <img src="../../static/mobile/default/images/goodsIcon06.png" onClick="editNum(this,'{{item.goods_id}}','up');" class="add"></div>

                    </div>
                </div>
            </div>
           
                </div>
            </div>
        </a>
    </li>
    {{/each}}
</script>
<script type="text/html" id="loseGoodsLi">
    {{each invalidList as item index}}
    <a href='/shop/goods/info/id/{{item.goods_id}}.html' >
        <div class="box">
            <img src="{{item.pic}}" alt="">
            <div class="info">
                <p class="fs28 color_9">{{item.goods_name}}</p>
                <span class="fs30 color_3">失效</span>
            </div>
        </div>
    </a>
    {{/each}}
</script>

  </div>

<script src="../../static/js/art-template.js"></script>
<script src="../../static/mobile/default/js/lib/fastclick.js"></script>
<script src="../../static/js/jquery/lazyload/jquery.lazyload.js"></script>
<script>
    $(function() {
        FastClick.attach(document.body);
		$("img.lazy").lazyload({effect:"fadeIn",event:"scroll",container:$(".page-bd")});
    });
</script>


<!-- 弹出领取优惠券 -->
<link rel="stylesheet" href="../../static/mobile/default/css/coupons.css"/>
<div class="model getCoupons" style="display: none;">
    <div class="modelContent">
        <div class="title fs36 fw_b color_3">请领取优惠券</div>
        <div class="list bonusList">
        </div>
        <div class="closeBtn fs32 fw_b color_w BGcolor_r" onclick="closeModel(this)">关闭</div>
    </div>
</div>
<script type="text/html" id="TabTpl">
    <div class="tabBox">
        <div class="tabBlock ">
            <div class="listBox">
                
                {{each list as item index}}
                <div class="block {{if item.receive_status !=2}}userTicket{{/if}}" data-type_id="{{item.type_id}}">
                    <div class="left">
                        <div class="fs34 fw_b">{{item.type_name}}</div>
                        <p class="fs26">满{{item.min_amount}}元可用</p>
                        <span class="fs24">{{item._use_start_date}}-{{item._use_end_date}}</span>
                    </div>
                    <div class="right">
                        <div class="fs38 money">
                            <p class="fw_b">￥</p><em class="fs60 num">{{item.type_money}}</em>
                        </div>
                        {{if item.receive_status==0}}<button class="fs24 active receive_do">立即领取</button>{{/if}}
                        {{if item.receive_status==1}}<button class="fs24 active use_do">去使用</button>{{/if}}
                        {{if item.receive_status==2}}<button class="fs24 active noNum">已抢光</button>{{/if}}
                    </div>
                </div>
                {{/each}}
                
            </div>
        </div>
    </div>
</script>
<script>
    //请求列表数据
    function getList(page,isagain) {
        $('.bonusList').append('<div class="get_list_tip">加载数据中...</div>');
        $.ajax({
            url:'/shop/api.bonus/getbonuslistreceivable.html',// 跳转到 action
            data:{goods_type:1,goods_id:0},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(res) {
                if(res.code  == 0 ){
                    _alert(res.errmsg);
                    $('.get_list_tip').html('加载失败，点击重新加载.');
                    return false;
                }
                $('.get_list_tip').remove();
                if (res.list){
                    $('.bonusList').append(template('TabTpl',res));
                    $('.bonusList').append('<div class="loadEnd">—— 没有更多啦，我是有底线的 ——</div>');
                }else{
                    $(".goCoupons").hide();
                }
            },error : function() {
                $('.get_list_tip').html('加载失败，点击重新加载.');
            }
        });
    }
   // getList();//执行加载
    $(function () {
        $(".goCouponsBtn").click(function (obj) {
            $('.getCoupons').show();
        })
        /*立即领券*/
        $(".bonusList").on('click','.receive_do',function () {
            var _this = $(this);
            var type_id = _this.parents('.block').data('type_id');
            var arr = new Object();
            arr.id=type_id;
            jq_ajax('/shop/api.bonus/receivefree.html',arr,function(res){
                if(res.code  == 0 ){
                    _alert(res.errmsg);
                }else if(res.code==2){
                    _alert('抱歉，优惠券已抢光！');
                    _this.text('已抢光');
                    _this.parents('.block').removeClass('userTicket');
                }else{
                    _this.removeClass('receive_do').addClass('use_do').text('去使用');
                }
            })
        });
        /*前往使用*/
        $(".bonusList").on('click','.use_do',function () {
            var _this = $(this);
            var type_id = _this.parents('.block').data('type_id');
            window.location.href='/shop/bonus/goodslist.html'+'?type_id='+type_id;
        });
    })
</script>

<script>
    var  orderIdList = ''
    //购物车统一请求
    function evalCart(action,arr){
        jq_ajax('https://mp.jianguoes.com/api/cart/getCart',arr,function(res){
           
            $('.top').find('em').html(res.cartTotal.goodsCount);
            $('.totel_price_1').html(res.cartTotal.checkedGoodsAmount);
            // $('.totel_price_2').html('.'+res.cartInfo.exp_total[1]);
            $('#buyNum').html(res.cartTotal.checkedGoodsCount);
            if (res.cartList){
                $('.emptyBox').hide();
                $('.goodslist ul').html(template('goodsLi',res));
            }else{
                $('.goodslist ul').html('');
                $('.emptyBox').show();
            }
            var sum = 0
            for(var i=0;i<res.cartList.length;i++){
                orderIdList = res.cartList
                if(res.cartList[i].checked ==1){
                    sum+=1
                }
            }

            if (res.cartList.length == sum){
                $('.checkall').prop("checked",true);
            }else{
                $('.checkall').prop('checked',false);
            }
            $('.loseGoods').find('.box').remove();
            if (res.invalidList){
                $('.loseGoods').show();
                $('.loseGoods').append(template('loseGoodsLi',res.cartInfo));
            }else{
                $('.loseGoods').hide();
            }
            container('.goodslist li');
            return true;
        },'get')
    }
    
     //统一购物车操作请求
    function updateCart(url,goodsId,is_select,that){
           var Data= {};
        if(url == 'https://mp.jianguoes.com/api/mp/updateCartChecked'){
            var checkGoodsId =''
        
            if(goodsId){
                if(that.is(':checked') == true){
                    for(var i =0;i<orderIdList.length;i++){
                        
                         if(orderIdList[i].checked == 1 ){
                             checkGoodsId+= orderIdList[i].goods_id+',' 
                        }
                        if( orderIdList[i].goods_id == goodsId ){
                              checkGoodsId+= orderIdList[i].goods_id+','
                        }
                  
                    }
                }else{
             
                        for(var i =0;i<orderIdList.length;i++){
                        if( orderIdList[i].goods_id == goodsId ){
                             orderIdList[i].checked = 0
                        }
                         if(orderIdList[i].checked == 1 ){
                             checkGoodsId+= orderIdList[i].goods_id+',' 
                        }
                  
                    }
                }
                
            }else{
                if(is_select ==1){
                for(var i =0;i<orderIdList.length;i++){
                    checkGoodsId+= orderIdList[i].goods_id+','
                }
            }
            }
             Data.goodsIds=checkGoodsId

            
        }else{
            
            Data.goodsId=goodsId;
            Data.number=1;
        }
           
        jq_ajax(url,Data,function(res){
            if (res.errno!=0){
                if (res.errmsg != '') _alert(res.errmsg);
                return false;
            }
            
         
            $('.top').find('em').html(res.data.cartTotal.goodsCount);
            $('.totel_price_1').html(res.data.cartTotal.checkedGoodsAmount);
            // $('.totel_price_2').html('.'+res.cartInfo.exp_total[1]);
            $('#buyNum').html(res.data.cartTotal.checkedGoodsCount);
            if (res.data.cartList){
                $('.emptyBox').hide();
                $('.goodslist ul').html(template('goodsLi',res.data));
            }else{
                $('.goodslist ul').html('');
                $('.emptyBox').show();
            }
              var sum = 0
            for(var i=0;i<res.data.cartList.length;i++){
                orderIdList = res.data.cartList
                if(res.data.cartList[i].checked ==1){
                    sum+=1
                }
            }

             if (res.data.cartList.length == sum){
                $('.checkall').prop("checked",true);
            }else{
                $('.checkall').prop('checked',false);
            }
            $('.loseGoods').find('.box').remove();
            if (res.invalidList){
                $('.loseGoods').show();
                $('.loseGoods').append(template('loseGoodsLi',res.data.cartInfo));
            }else{
                $('.loseGoods').hide();
            }
            container('.goodslist li');
            return true;
        },'get') 
          
    }
    
    //修改购物车订购数量
    function editNum(obj,rec_id,type) {
        var num = $(obj).parent().find('input').val();
        
        
          if (type == 'up'){
            num++;
            updateCart('https://mp.jianguoes.com/api/mp/addCart',rec_id);
           
        }else {
            num--;
        //      if (num <= 1){
        //      _alert('已经是最小数量')
        //   return false; 
        // }
            updateCart('https://mp.jianguoes.com/api/mp/minusCart',rec_id);
        }
       
        
    }
   
    //删除购物车商品
    $(document).on('click','.delect',function () {
        var rec_id = $(this).data('rec_id');
        return updateCart('https://mp.jianguoes.com/api/mp/addCart',rec_id);;
    })
    //清空购物车失效商品
    $('.clearInvalid').on('click',function () {
        return evalCart('clearInvalid');
    })
    //选择商品
    $('.goodslist').on('click','.check',function () {
        var is_select = 0;
        if ($(this).is(':checked')){
            is_select = 1;
        } 
        return updateCart('https://mp.jianguoes.com/api/mp/updateCartChecked',$(this).data('rec_id'),'',$(this));
    })
    //全选或全不选商品
    $('.checkall').on('click',function () {
        var is_select = 0;
        if ($(this).is(':checked') == true){
            is_select = 1;
        }
        return updateCart('https://mp.jianguoes.com/api/mp/updateCartChecked','',is_select );
    })
    //删除选择的商品
    $('.delSelGoods').on('click',function () {
        return updateCart('delSelGoods','');
    })
   

    $(function(){
        evalCart('getList');//加载购物车
        $('.top p').on('click',function(){
            if($(this).attr('data-type')==0){
                $(this).text('完成')
                $('.paying').hide();
                $('.edit').show();
                $(this).attr('data-type','1')
            }else{
                $(this).text('编辑')
                $('.edit').hide();
                $('.paying').show();
                $(this).attr('data-type','0')
            }
        })
        $(document).on('click','.like',function(){
            var imgObj = $(this).find('img');
			var status = imgObj.data('type');
			var goods_id = $(this).data('goods_id');
			jq_ajax('https://mp.jianguoes.com/api/mp/addorDelCollect', 'goods_id='+goods_id, function (res) {
				if (res.code == 0) {
					_alert(res.errmsg);
					return false;
				}
				if (status == 0) {
					imgObj.attr('src', '/static/mobile/default/images/goodsIcon03_lh.png')
					imgObj.data('type', '1')
				} else {
					imgObj.attr('src', '/static/mobile/default/images/goodsIcon03.png')
					imgObj.data('type', '0')
				}
			},'get');

        })
    })
    function closeModel(obj){
        $(obj).parents('.model').hide()
    }
</script>

  <div class="alertBox">
      <div class="alertBG"></div>
      <div class="alert">
          <div class="text fs30 color_3 bor_b">

          </div>
          <!-- 单按钮 -->
          <div class="button fs32 fw_b color_r">
              知道了
          </div>
          <!-- 双按钮 -->
          <div class="buttonBox fs32 fw_b">
              <span class="color_9 bor_r cancel">取消</span>
              <span class="color_r confirm">确定</span>
          </div>
      </div>
  </div>
  <script type="text/javascript">
      var is_xcx = 0;
      $(document).on('click', 'a', function () {
          var href = $(this).attr('href');
          if (href.indexOf('/pages') != -1) {
              if (is_xcx == 1) {
                  wx.miniProgram.navigateTo({
                      url: href
                  })
                  return false;
              } else {
                  return false;
              }
          }
      })
  </script>
    </body>
</html>